/** 现货市场 */

import { requestSDspotMarket } from "./fetch";
import { DataSourceTypeEnum } from "@src/globalData/enum";
import {
  processingDataFormat,
  initDataDul,
} from "@src/dataFormatConversion/formatData";

import dayjs from "dayjs";

import type { SpotMarketReqFn } from "@src/entries/background/type";
import { promisetTimeOut } from "@src/utils/common";
// import { saveOneWithoutCal } from "@src/dataFormatConversion/saveOneWithoutCal";
// import { saveFengZe } from "@src/spotMarketPrivateData/generate";


/**MOCK数据请求  !!!别删除用于MOCK爬虫 上生产注释就行*/
// import { 
      // isVal24Mock, 
      // marketDisclosurePreClearanceMock,
      // marketDisclosureZeroHourMock, 
      // storageDataMock, 
      // beiyongOneMock, 
      // beiyongTwoMock, 
      // aheadOffonInfoMock,
      // realtimeRegulatedInfoMock,
  //     realtimeNodePriceInfoMock 
  //  } from '@src/dataFormatConversion/data'
// export const init = () => {
//   /**执行爬虫定时存储 */
//   processingDataFormat (DataSourceTypeEnum.AHEAD_MARKET_BEFORE_INFO,marketDisclosurePreClearanceMock,'2023-03-27')
//   processingDataFormat (DataSourceTypeEnum.REALTIME_MARKET_INFO,marketDisclosurePreClearanceMock,'2023-03-27')
//   processingDataFormat (DataSourceTypeEnum.ACT_MARKET_INFO,marketDisclosurePreClearanceMock,'2023-03-27')
//   processingDataFormat (DataSourceTypeEnum.AHEAD_USER_PRICE_INFO,isVal24Mock,'2023-03-27')
//   processingDataFormat (DataSourceTypeEnum.REALTIME_USER_PRICE_INFO,isVal24Mock,'2023-03-27')
//   processingDataFormat (DataSourceTypeEnum.ACT_USER_PRICE_INFO,isVal24Mock,'2023-03-27')
//   processingDataFormat (DataSourceTypeEnum.REALTIME_BACKUP_PREDICT_INFO,beiyongOneMock,'2023-03-27')
//   processingDataFormat (DataSourceTypeEnum.REALTIME_BACKUP_INFO,beiyongTwoMock,'2023-03-27')
//   processingDataFormat (DataSourceTypeEnum.ACT_BACKUP_INFO,beiyongTwoMock,'2023-03-27')
//   processingDataFormat (DataSourceTypeEnum.AHEAD_OFFON_INFO,aheadOffonInfoMock,'2023-03-27')
//   processingDataFormat (DataSourceTypeEnum.AHEAD_REGULATED_INFO,realtimeRegulatedInfoMock,'2023-03-27')
//      processingDataFormat (DataSourceTypeEnum.REALTIME_NODE_PRICE_INFO,realtimeNodePriceInfoMock,'2023-03-27')
// };
// if(import.meta.env.VITE_APP_ENV==='development') init()

// 更新昨日实时  2  打开插件 D日传昨天

/**
 * 处理 用户侧结算价-日前、用户侧结算价（实时-临时）、用户侧结算价（实时-正式） 
 * 新旧版控制
 */
const controlOldNew = async (list:Promise<any>[])=> {
  const priorityLevel:number = 1 // 优先级：0 旧；1 新。
  const dataList = await Promise.allSettled(list)

  if(priorityLevel === 0) {
    if(dataList[0].status === 'fulfilled') return Promise.resolve(dataList[0].value)
    if(dataList[1].status === 'fulfilled') return Promise.resolve(dataList[1].value)
    return Promise.reject('controlOldNew error')
  }

  if(dataList[1].status === 'fulfilled') return Promise.resolve(dataList[1].value)
  if(dataList[0].status === 'fulfilled') return Promise.resolve(dataList[0].value)
  return Promise.reject('controlOldNew error')
}

export const spotMarketCommon: Partial<Record<string, Function>> = {
  /**
   * 修改后端 session 中的全局的时间
   * https://pmos.sd.sgcc.com.cn:18080/trade/main/home/changeDate.do?pdate=2024-03-12&_=1711625429719
   */
  sdSpotMarketChangeDate: async (pdate: string | number) => {
    const date = dayjs(pdate).format("YYYY-MM-DD");
    try {
      await requestSDspotMarket(
       `https://pmos.sd.sgcc.com.cn:18080/trade/main/home/changeDate.do?pdate=${date}&_=${new Date().getTime()}`,
       undefined,
       { method: "GET" }
     );
     await promisetTimeOut(300)
    }catch(e) {
      console.error(e)
    }
  }
};

export const spotMarketBatch: Partial<Record<DataSourceTypeEnum, SpotMarketReqFn>> = {
  /**
   * 【现货市场】-【现货交易】-【日前交易结果】-【一次日前节点电价查询】
   * 全网所有节点日前出清节点电价
   * D + 1
   * AHEAD_NODE_PRICE_INFO = "ahead_node_price_info"
   */
     [DataSourceTypeEnum.AHEAD_NODE_PRICE_INFO]: async ({ headers, unitid }) => {
       try {
        const data = await requestSDspotMarket(
          `https://pmos.sd.sgcc.com.cn:18080/trade/DascrqcqCx.do?method=getNodePrice&nodeid=${unitid}`,
          { method: "getNodePrice" },
          { headers }
        )
        return Promise.resolve(data)
      } catch(e) {
       console.log('error ahead_node_price_info nodeId', unitid)
       console.error(e)
       return Promise.reject(e)
      }
     },
  /**
   * https://pmos.sd.sgcc.com.cn:18080/trade/main/home/changeDate.do?pdate=2024-03-19&_=1711692352927
   * 【现货市场】-【现货交易】-【实时交易结果】-【实时节点电价查询】
   * 全网所有节点实时出清节点电价-临时
   * D - 1
   * ACT_NODE_PRICE_INFO = "act_node_price_info",
   */
     [DataSourceTypeEnum.ACT_NODE_PRICE_INFO]: async ({ headers, unitid }) => {
       try {
         const data = await requestSDspotMarket(
           `https://pmos.sd.sgcc.com.cn:18080/trade/YxscrqcqCx.do?method=getNodePrice&nodeid=${unitid}`,
           { method: "getNodePrice" },
           { headers }
         )
         return Promise.resolve(data)
       } catch(e) {
        console.log('error act_node_price_info nodeId', unitid)
        console.error(e)
        return Promise.reject(e)
       }
     }
}

export const spotMarket: Partial<Record<DataSourceTypeEnum, SpotMarketReqFn>> = {
 /** V1
   * 【现货市场】-【现货交易】-【市场信息披露】-【电网运行预测信息】
   * 市场披露信息（预测-出清前）（包括：直调负荷、地方电厂发电总加、联络线受电负荷、风电总加、光伏总加、非市场化核电总加、自备机组总加、试验机组总加）
   * AHEAD_MARKET_BEFORE_INFO = "ahead_market_before_info",
   */
    [DataSourceTypeEnum.AHEAD_MARKET_BEFORE_INFO]: async ({ headers, reqType, pdate, calculateSaveData = true }) => {
      let data = {};
      try {
        data = await requestSDspotMarket(
          "https://pmos.sd.sgcc.com.cn:18080/trade/DaJyxxPlDa.do?method=getChart",
          { method: "getChart" },
          { headers }
        );
        self?.LogDB?.addHistory({
          code:DataSourceTypeEnum.AHEAD_MARKET_BEFORE_INFO,
          statement:`【现货市场】-【现货交易】-【市场信息披露】-【电网运行预测信息】市场披露信息（预测-出清前）（包括：直调负荷、地方电厂发电总加、联络线受电负荷、风电总加、光伏总加、非市场化核电总加、自备机组总加、试验机组总加）`,
          pdate,
          query:data
        })
        console.log(`   * 【现货市场】-【现货交易】-【市场信息披露】-【电网运行预测信息】`)
        console.log(`   * 市场披露信息（预测-出清前）（包括：直调负荷、地方电厂发电总加、联络线受电负荷、风电总加、光伏总加、非市场化核电总加、自备机组总加、试验机组总加）`)
        console.log('pdate', pdate)
        console.log('data', data)
        return Promise.resolve({
          data,
          pdate
        })
      } finally {
        calculateSaveData && processingDataFormat(
          DataSourceTypeEnum.AHEAD_MARKET_BEFORE_INFO,
          data,
          pdate
        );
      }
    },
    /** V1
     *【现货市场】-【现货交易】-【市场信息披露】-【电网运行实际信息（临时数据）】
     * 市场披露信息（实际-临时）（包括：直调负荷、地方电厂发电总加、联络线受电负荷、风电总加、光伏总加、抽蓄、非市场化核电总加、自备机组、试验机组总加）
     * REALTIME_MARKET_INFO = "realtime_market_info",
     */
    [DataSourceTypeEnum.REALTIME_MARKET_INFO]: async ({ headers, reqType, pdate, calculateSaveData = true }) => {
      let data = {};
      try {
        data = await requestSDspotMarket(
          "https://pmos.sd.sgcc.com.cn:18080/trade/DaJyxxPlYxTmp.do?method=getChart",
          { method: "getChart" },
          { headers }
        );
        self?.LogDB?.addHistory({
          code:DataSourceTypeEnum.REALTIME_MARKET_INFO,
          statement:'【现货市场】-【现货交易】-【市场信息披露】-【电网运行实际信息（临时数据）】市场披露信息（实际-临时）（包括：直调负荷、地方电厂发电总加、联络线受电负荷、风电总加、光伏总加、抽蓄、非市场化核电总加、自备机组、试验机组总加）',
          pdate,
          query:data
        })
        console.log(`   *【现货市场】-【现货交易】-【市场信息披露】-【电网运行实际信息（临时数据）】`)
        console.log(`   * 市场披露信息（实际-临时）（包括：直调负荷、地方电厂发电总加、联络线受电负荷、风电总加、光伏总加、抽蓄、非市场化核电总加、自备机组、试验机组总加）`)
        console.log('pdate', pdate)
        console.log('data', data)
        return Promise.resolve({
          data,
          pdate
        })
      } finally {
        calculateSaveData && processingDataFormat(
          DataSourceTypeEnum.REALTIME_MARKET_INFO,
          data,
          pdate
        );
      }
    },
    /** V1
     * 【现货市场】-【现货交易】-【市场信息披露】-【电网运行实际信息】
     * 市场披露信息（实际-正式）（包括：直调负荷、地方电厂发电总加、联络线受电负荷、风电总加、光伏总加、抽蓄、非市场化核电总加、自备机组、试验机组总加）
     * ACT_MARKET_INFO = "act_market_info",
     */
    [DataSourceTypeEnum.ACT_MARKET_INFO]: async ({ headers, reqType, pdate, calculateSaveData = true }) => {
      let data = {};
      try {
        data = await requestSDspotMarket(
          "https://pmos.sd.sgcc.com.cn:18080/trade/DaJyxxPlYx.do?method=getChart",
          { method: "getChart" },
          { headers }
        );
        self?.LogDB?.addHistory({
          code:DataSourceTypeEnum.ACT_MARKET_INFO,
          statement:`【现货市场】-【现货交易】-【市场信息披露】-【电网运行实际信息】市场披露信息（实际-正式）（包括：直调负荷、地方电厂发电总加、联络线受电负荷、风电总加、光伏总加、抽蓄、非市场化核电总加、自备机组、试验机组总加）`,
          pdate,
          query:data
        })
        console.log(`   * 【现货市场】-【现货交易】-【市场信息披露】-【电网运行实际信息】`)
        console.log(`   * 市场披露信息（实际-正式）（包括：直调负荷、地方电厂发电总加、联络线受电负荷、风电总加、光伏总加、抽蓄、非市场化核电总加、自备机组、试验机组总加）`)
        console.log('pdate', pdate)
        console.log('data', data)
        return Promise.resolve({
          data,
          pdate
        })
      } finally {
        calculateSaveData && processingDataFormat(
          DataSourceTypeEnum.ACT_MARKET_INFO, 
          data, 
          pdate
        );
      }
    },
  
    /** V1
     * 【现货市场】-【现货交易】-【交易组织监控】-【日前交易结果】
     * 用户侧结算价-日前
     * AHEAD_USER_PRICE_INFO = "ahead_user_price_info",
     */
    [DataSourceTypeEnum.AHEAD_USER_PRICE_INFO]: async ({ headers, reqType, pdate, unitid, calculateSaveData = true }) => {
      let data = {};
      try {
        data = await controlOldNew([
          requestSDspotMarket(
          `https://pmos.sd.sgcc.com.cn:18080/trade/DsjscRqjyjgDetail.do?method=getYdcdjLine&unitid=${unitid}`,
          { method: "getYdcdjLine" },
          { headers }
        ),
        // 新版
        requestSDspotMarket(
          `https://pmos.sd.sgcc.com.cn:18080/trade/DsjscRqjyjgDetail.do?method=getYdcdjLine&unitid=${unitid}`,
          { method: "getYdcdjLine" },
          { headers }
        )
        ])
        self?.LogDB?.addHistory({
          code:DataSourceTypeEnum.AHEAD_USER_PRICE_INFO,
          statement:`用户侧结算价-日前 【现货市场】-【现货交易】-【交易组织监控】-【日前交易结果】`,
          pdate,
          query:data
        })
        console.log(`   * 【现货市场】-【现货交易】-【交易组织监控】-【日前交易结果】`)
        console.log(`   * 用户侧结算价-日前`)
        console.log('pdate', pdate)
        console.log('data', data)
        return Promise.resolve({
          data,
          pdate
        })
      } finally {
        calculateSaveData && processingDataFormat(
          DataSourceTypeEnum.AHEAD_USER_PRICE_INFO,
          data,
          pdate
        );
      }
    },
    /** V1
     * 【现货市场】-【现货交易】-【交易组织监控】-【实时交易结果】
     * 用户侧结算价（实时-正式）
     * ACT_USER_PRICE_INFO = "act_user_price_info",
     */
    [DataSourceTypeEnum.ACT_USER_PRICE_INFO]: async ({ headers, reqType, pdate, unitid, calculateSaveData = true }) => {
      let data = {};
      try {
        data = await controlOldNew([
            requestSDspotMarket(
          `https://pmos.sd.sgcc.com.cn:18080/trade/DsjscSsjyjgDetail.do?method=getYdcdjLine&unitid=${unitid}`,
          { method: "getYdcdjLine" },
          { headers }
        ),
        // 新版
        requestSDspotMarket(
          `https://pmos.sd.sgcc.com.cn:18080/trade/DsjscSsjyjgDetail.do?method=getYdcdjLine&unitid=${unitid}`,
          { method: "getYdcdjLine" },
          { headers }
        )
      ])
      self?.LogDB?.addHistory({
        code:DataSourceTypeEnum.ACT_USER_PRICE_INFO,
        statement:`用户侧结算价（实时-正式）【现货市场】-【现货交易】-【交易组织监控】-【实时交易结果】`,
        pdate,
        query:data
      })
        console.log(`   * 【现货市场】-【现货交易】-【交易组织监控】-【实时交易结果】`)
        console.log(`   * 用户侧结算价（实时-正式）`)
        console.log('pdate', pdate)
        console.log('data', data)
        return Promise.resolve({
          data,
          pdate
        })
      } finally {
        calculateSaveData && processingDataFormat(
          DataSourceTypeEnum.ACT_USER_PRICE_INFO, 
          data, 
          pdate
        );
      }
    },

  /** V2
   * 【现货市场】-【现货交易】-【市场信息披露】-【电网运行预测信息】
   * 备用信息（预测-出清前）
   * REALTIME_BACKUP_PREDICT_INFO = "realtime_backup_predict_info",
   */
  [DataSourceTypeEnum.REALTIME_BACKUP_PREDICT_INFO]: async ({ headers, reqType, pdate, calculateSaveData = true }) => {
    let data = {};
    try {
      data = await requestSDspotMarket(
        "https://pmos.sd.sgcc.com.cn:18080/trade/DaJyxxPlDa.do?method=getByList&type=%E6%AD%A3%E5%A4%87%E7%94%A8",
        { method: 'getByList', type: '正备用' },
        { headers }
      );
      self?.LogDB?.addHistory({
        code:DataSourceTypeEnum.REALTIME_BACKUP_PREDICT_INFO,
        statement:`备用信息（预测-出清前）【现货市场】-【现货交易】-【市场信息披露】-【电网运行预测信息】`,
        pdate,
        query:data
      })
      console.log(`    V2【现货市场】-【现货交易】-【市场信息披露】-【电网运行预测信息】`)
      console.log(`    V2 备用信息（预测-出清前）`)
      console.log('pdate', pdate)
      console.log('data', data)
      return Promise.resolve({
          data,
          pdate
      })
    } finally {
      calculateSaveData && processingDataFormat(
        DataSourceTypeEnum.REALTIME_BACKUP_PREDICT_INFO,
        data,
        pdate
      );
    }
  },
  /**
   * 【现货市场】-【现货交易】-【市场信息披露】-【电网运行预测信息】
   * 必开必停机组信息（预测-出清前)
   */
  [DataSourceTypeEnum.AHEAD_OFFON_INFO]: async ({ headers, reqType, pdate, calculateSaveData = true }) => {
    let data = {};
    try {
      data = await requestSDspotMarket(
        "https://pmos.sd.sgcc.com.cn:18080/trade/DaJyxxPlDa.do?method=getTsjzList",
        { method: 'getTsjzList' },
        { headers }
      );
      self?.LogDB?.addHistory({
        code:DataSourceTypeEnum.AHEAD_OFFON_INFO,
        statement:`必开必停机组信息（预测-出清前）【现货市场】-【现货交易】-【市场信息披露】-【电网运行预测信息】`,
        pdate,
        query:data
      })
      console.log(`   * 【现货市场】-【现货交易】-【市场信息披露】-【电网运行预测信息】`)
      console.log(`   *  必开必停机组信息（预测-出清前）`)
      console.log('pdate', pdate)
      console.log('data', data)
      return Promise.resolve({
          data,
          pdate
      })
    } finally {
      calculateSaveData && processingDataFormat(
        DataSourceTypeEnum.AHEAD_OFFON_INFO,
        data,
        pdate
      );
    }
  },
  /** V2
   * 【现货市场】-【现货交易】-【市场信息披露】-【电网运行预测信息】
   * 事前监管（预测-出清前）
   * AHEAD_REGULATED_INFO = "ahead_regulated_info",
   */
    [DataSourceTypeEnum.AHEAD_REGULATED_INFO]: async ({ headers, reqType, pdate, calculateSaveData = true }) => {
      let data = {};
      try {
        data = await requestSDspotMarket(
          "https://pmos.sd.sgcc.com.cn:18080/trade/DaJyxxPlDa.do?method=getSqjgList",
          { method: 'getSqjgList', type: '正备用' },
          { headers }
        );
        self?.LogDB?.addHistory({
          code:DataSourceTypeEnum.AHEAD_REGULATED_INFO,
          statement:`事前监管（预测-出清前）【现货市场】-【现货交易】-【市场信息披露】-【电网运行预测信息】`,
          pdate,
          query:data
        })
        console.log(`   V2【现货市场】-【现货交易】-【市场信息披露】-【电网运行预测信息】`)
        console.log(`   V2 事前监管（预测-出清前）`)
        console.log('pdate', pdate)
        console.log('data', data)
        return Promise.resolve({
          data,
          pdate
        })
      } finally {
        calculateSaveData && processingDataFormat(
          DataSourceTypeEnum.AHEAD_REGULATED_INFO,
          data,
          pdate
        );
      }
    },
  /** V2
   * 【现货市场】-【现货交易】-【市场信息披露】-【电网运行实际信息（临时数据）】
   * 备用信息（实际-临时)
   * REALTIME_BACKUP_INFO = 'realtime_backup_info',
   */
    [DataSourceTypeEnum.REALTIME_BACKUP_INFO]: async ({ headers, reqType, pdate, calculateSaveData = true }) => {
      let data = {};
      try {
        data = await requestSDspotMarket(
          "https://pmos.sd.sgcc.com.cn:18080/trade/DaJyxxPlYxTmp.do?method=getByList&type=%E6%AD%A3%E5%A4%87%E7%94%A8",
          { method: 'getByList', type: '正备用' },
          { headers }
        );
        self?.LogDB?.addHistory({
          code:DataSourceTypeEnum.REALTIME_BACKUP_INFO,
          statement:`备用信息（实际-临时) 现货市场】-【现货交易】-【市场信息披露】-【电网运行实际信息（临时数据）】`,
          pdate,
          query:data
        })
        console.log(`    V2 现货市场】-【现货交易】-【市场信息披露】-【电网运行实际信息（临时数据）】`)
        console.log(`    V2 备用信息（实际-临时)`)
        console.log('pdate', pdate)
        console.log('data', data)
        return Promise.resolve({
          data,
          pdate
        })
      } finally {
        calculateSaveData && processingDataFormat(
          DataSourceTypeEnum.REALTIME_BACKUP_INFO,
          data,
          pdate
        );
      }
    },

  /** V2
   * 【现货市场】-【现货交易】-【市场信息披露】-【电网运行实际信息】
   * 备用信息（实际-正式）
   * ACT_BACKUP_INFO = "act_backup_info",
   */
  [DataSourceTypeEnum.ACT_BACKUP_INFO]: async ({ headers, reqType, pdate, calculateSaveData = true }) => {
    let data = {};
    try {
      data = await requestSDspotMarket(
        "https://pmos.sd.sgcc.com.cn:18080/trade/DaJyxxPlYx.do?method=getByList&type=%E6%AD%A3%E5%A4%87%E7%94%A8",
        { method: "getByList" },
        { headers }
      );
      self?.LogDB?.addHistory({
        code:DataSourceTypeEnum.ACT_BACKUP_INFO,
        statement:`备用信息（实际-正式）【现货市场】-【现货交易】-【市场信息披露】-【电网运行实际信息】`,
        pdate,
        query:data
      })
      console.log(`   V2【现货市场】-【现货交易】-【市场信息披露】-【电网运行实际信息】`)
      console.log(`   V2 备用信息（实际-正式）`)
      console.log('pdate', pdate)
      console.log('data', data)
      return Promise.resolve({
          data,
          pdate
      })
    } finally {
      calculateSaveData && processingDataFormat(
        DataSourceTypeEnum.ACT_BACKUP_INFO, 
        data, 
        pdate
      );
    }
  },

 /** V1
   * 【现货市场】-【现货交易】-【实时交易结果】-【实时交易结果查询（临时）】
   * 用户侧结算价（实时-临时）
   * REALTIME_USER_PRICE_INFO = "realtime_user_price_info"
   */
  [DataSourceTypeEnum.REALTIME_USER_PRICE_INFO]: async ({ headers, reqType, pdate, unitid, calculateSaveData = true }) => {
    let data = {};
    try {
      data = await controlOldNew([
        requestSDspotMarket(
        `https://pmos.sd.sgcc.com.cn:18080/trade/YxJyjgfbPlantTmpQuery.do?method=getPowerPrice&unitid=${unitid}`,
        { method: "getPowerPrice" },
        { headers }
      ),
      // 新版
      requestSDspotMarket(
        `https://pmos.sd.sgcc.com.cn:18080/trade/YxJyjgfbPlantTmpQuery24.do?method=getPowerPrice&unitid=${unitid}`,
        { method: "getPowerPrice" },
        { headers }
      )
      ])
      self?.LogDB?.addHistory({
        code:DataSourceTypeEnum.REALTIME_USER_PRICE_INFO,
        statement:`用户侧结算价（实时-临时）【现货市场】-【现货交易】-【实时交易结果】-【实时交易结果查询（临时）】`,
        pdate,
        query:data
      })
      console.log(`   * 【现货市场】-【现货交易】-【实时交易结果】-【实时交易结果查询（临时）】`)
      console.log(`   * 用户侧结算价（实时-临时）`)
      console.log('pdate', pdate)
      console.log('data', data)
      return Promise.resolve({
          data,
          pdate
      })
    } finally {
      calculateSaveData && processingDataFormat(
        DataSourceTypeEnum.REALTIME_USER_PRICE_INFO,
        data,
        pdate
      );
    }
  },
 /** V2
   * 【现货市场】-【现货交易】-【实时交易结果】-【实时交易结果查询（临时）】
   * 节点电价（实时-临时）
   * REALTIME_NODE_PRICE_INFO = "realtime_node_price_info",
   */
  [DataSourceTypeEnum.REALTIME_NODE_PRICE_INFO]: async ({ headers, reqType, pdate, unitid, calculateSaveData = true }) => {
    let data = {};
    try {
      data = await requestSDspotMarket(
        `https://pmos.sd.sgcc.com.cn:18080/trade/YxJyjgfbPlantTmpQuery.do?method=getDetail&unitid=${unitid}`,
        { method: "getDetail" },
        { headers }
      );
      self?.LogDB?.addHistory({
        code:DataSourceTypeEnum.REALTIME_NODE_PRICE_INFO,
        statement:`节点电价（实时-临时）【现货市场】-【现货交易】-【实时交易结果】-【实时交易结果查询（临时）】`,
        pdate,
        query:data
      })
      console.log(`   V2 【现货市场】-【现货交易】-【实时交易结果】-【实时交易结果查询（临时）】`)
      console.log(`   V2  节点电价（实时-临时）`)
      console.log('pdate', pdate)
      console.log('data', data)
      return Promise.resolve({
          data,
          pdate
      })
    } finally {
      calculateSaveData && processingDataFormat(
        DataSourceTypeEnum.REALTIME_NODE_PRICE_INFO,
        data,
        pdate
      );
      // saveType === 2 && saveOneWithoutCal(
      //   DataSourceTypeEnum.REALTIME_NODE_PRICE_INFO,
      //   data,
      //   pdate
      // );
      // saveFengZe(data, pdate)
    }
  },

  // 全省节点电价（日前）D+1
  [DataSourceTypeEnum.AHEAD_NODE_AVG_PRICE_INFO]: async ({ headers, reqType, pdate, unitid, calculateSaveData = true }) => {
    let data = {};
    try {
      data = await requestSDspotMarket(
        `https://pmos.sd.sgcc.com.cn:18080/trade/DascrqcqCx.do?method=getGrid&nodeid=root&draw=1&start=0&length=-1&_=${new Date().getTime()}`,
       undefined,
        { headers, method:'GET' }
      );
      self?.LogDB?.addHistory({
        code:DataSourceTypeEnum.AHEAD_NODE_AVG_PRICE_INFO,
        statement:`全省节点电价（日前）D+1`,
        pdate,
        query:data
      })
      console.log(`   全省节点电价（日前）D+1`)
      console.log('pdate', pdate)
      console.log('data', data)
      return Promise.resolve({
          data,
          pdate
      })
    } finally {
      calculateSaveData && processingDataFormat(
        DataSourceTypeEnum.AHEAD_NODE_AVG_PRICE_INFO,
        data,
        pdate
      );
    }
  },

  // 全省节点电价（实时）D-1
  [DataSourceTypeEnum.ACT_NODE_AVG_PRICE_INFO]: async ({ headers, reqType, pdate, unitid, calculateSaveData = true }) => {
    let data = {};
    try {
      data = await requestSDspotMarket(
        `https://pmos.sd.sgcc.com.cn:18080/trade/YxscrqcqCx.do?method=getGrid&nodeid=root&draw=1&start=0&length=-1&_=${new Date().getTime()}`,
       undefined,
        { headers, method:'GET' }
      );
      self?.LogDB?.addHistory({
        code:DataSourceTypeEnum.ACT_NODE_AVG_PRICE_INFO,
        statement:`全省节点电价（实时）D-1`,
        pdate,
        query:data
      })
      console.log(`  全省节点电价（实时）D-1`)
      console.log('pdate', pdate)
      console.log('data', data)
      return Promise.resolve({
          data,
          pdate
      })
    } finally {
      calculateSaveData && processingDataFormat(
        DataSourceTypeEnum.ACT_NODE_AVG_PRICE_INFO,
        data,
        pdate
      );
    }
  }
};


/**数据格式初始化 */
initDataDul()
